SQL

Datediff Sql Compare two dates

Datediff Sql Compare two dates, someone asked me to explain?
SQL

In this article, I will explain how to compare two dates and gets number of days using Datediff in SQL server.

The DATEDIFF() function will return the number of days between two dates.

Syntax:

SELECT DATEDIFF(day,startDate,endDate)

Example:

DECLARE @startDate DATETIME
DECLARE @endDate DATETIME

SET @startDate ='2016-05-15'
SET @endDate ='2016-09-16'


SELECT DATEDIFF(DD, @startDate, @endDate) AS DayDiffrence 

Output:

Datediff Sql Compare two dates

Post your comments / questions